package org.reliablesource.prism.ui.adapters;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.reliablesource.prism.core.IPrismScreen;

/**
 *
 *  PrismScreenPropertySourceAdapter.java
 *  Copyright (c) 2006, Reliable Source, Inc. All Rights Reserved
 *
 *	Created on: Apr 25, 2006 
 *  @author Dennis Park <a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 */

public class PrismScreenPropertySourceAdapter implements IPropertySource{
	final protected List descriptorsList;

	final protected List mergedDescriptorsList;
	final private IPrismScreen screen;
	
	public PrismScreenPropertySourceAdapter(IPrismScreen _screen){
		super();
		Assert.isNotNull(_screen);
		descriptorsList = new ArrayList();
		mergedDescriptorsList = new ArrayList();
		this.screen = _screen;
	}
	
	public Object getEditableValue() {
		return null;
	}

	public IPropertyDescriptor[] getPropertyDescriptors() {
		
		PropertyDescriptor pd = new PropertyDescriptor(IPrismScreen.CURSOR_START_PT, "Animation Start Point:");
		pd.setLabelProvider(new ILabelProvider(){
			
			public Image getImage(Object element) {
				return null;
			}

			public String getText(Object element) {
				StringBuffer buffer = new StringBuffer();
				Point p = (Point)element;				
				return buffer.append("(" + p.x + "," + p.y + ")").toString();
			}

			public void addListener(ILabelProviderListener listener) {
			}

			public void dispose() {
			}

			public boolean isLabelProperty(Object element, String property) {
				return false;
			}

			public void removeListener(ILabelProviderListener listener) {
			}
			
		});
		
		return new IPropertyDescriptor[] { 
				new PropertyDescriptor(IPrismScreen.IMAGE_PATH, "Image Location:"),
				pd, 
				new PropertyDescriptor(IPrismScreen.ANNOTATIONS, "Annotations:")
		};
	}

	public Object getPropertyValue(Object propertyId) {
		if (IPrismScreen.IMAGE_PATH.equals(propertyId))
			return screen.getImageFilePath() + screen.getName() + "." + screen.getImageFileType();
		else if(IPrismScreen.CURSOR_START_PT.equals(propertyId))
			return screen.getPointerStart();
		else if(IPrismScreen.CURSOR_PTS.equals(propertyId))
			return screen.getPathLocationsList();
		else if(IPrismScreen.ANNOTATIONS.equals(propertyId))
			return screen.getAnnotationsList();		
		return null;
	}

	public boolean isPropertySet(Object id) {
		return false;
	}

	public void resetPropertyValue(Object id) {
		
	}

	public void setPropertyValue(Object id, Object value) {
		
	}

}
